<template>
	<view class="warp">
		<!-- #ifdef APP-PLUS -->
		<view class="title-contents"><view class="top-view status"></view></view>
		<!-- #endif -->
		<view class="login-title">
			<view class="logo"><image src="/static/images/common/logo.png" mode=""></image></view>
		</view>
		<!-- 密码登录 -->
		<view class="login-phone form-wapper">
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-shouji"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" v-model="username" type="number" placeholder="请输入手机号" /></view>
			</view>
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-yanzhengma"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" v-model="vercode" type="number" placeholder="请输入验证码" /></view>

				<view><button type="default" @click="getSendSms()">获取验证码</button></view>
			</view>
			<view class="code input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="rside">
					<input placeholder-class="input-placeholder" name="password" v-model="password" type="password" maxlength="12" placeholder="请输入密码(6-12位) " />
				</view>
			</view>
		</view>

		<button type="primary" class="login-btn" @click="getRegistered()" >注册</button>
		<view class="reg-paw"><text class="active" @click="back">已有账号,返回登录</text></view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			username: '',
			password: '',
			vercode: '',
			urls: 'https://4de16698-d9f4-443a-b416-ef1037cce952.bspapp.com/http'
		};
	},
	onLoad() {},
	methods: {
		// 注册
		getRegistered() {
			uni.request({
				url: this.urls + '/user/reg',
				header: {
					'content-type': 'application/x-www-form-urlencoded'
				},
				data: {
					username: this.username,
					password: this.password,
					vercode: this.vercode
				},
				success: res => {
					console.log(res.data);
					if (res.data.code == 0) {
						// 注册成功
						uni.showToast({
							title: '注册成功',
							duration: 2000
						});
						// 存放到本地
						uni.setStorage({
							key: 'token',
							data: res.data.token
						});
						// 返回
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/public/login'
							});
						}, 1000);
					}
				},
				fail: err => {
					console.log(err);
				}
			});
		},
		// 验证码
		getSendSms() {
			uni.request({
				url: this.urls + '/user/sendSms',
				header: {
					'content-type': 'application/x-www-form-urlencoded'
				},
				data: {
					mobile: this.username,
					type: 'register'
				},
				success: res => {
					console.log(res.data);
				},
				fail: err => {
					console.log(err);
				}
			});
		}
	}
};
</script>
<style lang="scss">
@import 'login.scss';
</style>
